﻿Imports BUS
Imports DTO
Imports System.Data.OleDb

Public Class GhiNhanMatSach

    Private Sub btnthoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnthoat.Click
        Close()
    End Sub

    'Public Sub LoadData()
    '    Dim strSQL As String = "SELECT NhanVien.HoTenNV, Sach.TenSach, DocGia.HoTenDG, MatSach.NgayGhiNhan, MatSach.TienPhat FROM(((DocGia INNER JOIN MatSach ON DocGia.MaDocGia = MatSach.MaDG) INNER JOIN NhanVien ON DocGia.MaNV = NhanVien.MaNV) INNER JOIN Sach ON MatSach.MaSach = Sach.MaSach)"
    '    Dim dataset As DataTable = New DataTable()

    '    Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=QUANLYTHUVIEN.accdb")
    '    Dim cmd As OleDbCommand = New OleDbCommand(strSQL, con)
    '    Dim ad As OleDbDataAdapter = New OleDbDataAdapter(cmd)
    '    'ad.Fill(dataset)
    '    'DataGridView_hosonhanvien.AutoGenerateColumns = False
    '    'DataGridView_hosonhanvien.DataSource = dataset


    '    'Dim ds As List(Of NhanVienDTO)
    '    'Dim bus As New NhanVienBUS()
    '    'ds = bus.LayNhanVien()
    '    'DataGridView_hosonhanvien.Rows.Clear()
    '    'For i As Integer = 0 To ds.Count - 1
    '    '    DataGridView_hosonhanvien.Rows.Add(ds(i).MaNV, ds(i).HoTen, ds(i).DienThoai, ds(i).DiaChi, ds(i).NgaySinh, ds(i).MaBoPhan, ds(i).MaBangCap, ds(i).MaChucVu)
    '    'Next

    'End Sub

    Private Sub GhiNhanMatSach_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        Dim nhanvien As New NhanVienBUS()
        Dim ds1 As New List(Of NhanVienDTO)
        ds1 = nhanvien.LayNhanVien()
        Cb_nguoighinnhan.DataSource = ds1
        Cb_nguoighinnhan.DisplayMember = "HoTenNV"
        Cb_nguoighinnhan.ValueMember = "MaNV"
        Cb_nguoighinnhan.SelectedIndex = 0


        Dim docgia As New DocGiaBUS_1()
        Dim ds2 As New List(Of DocGiaDTO)
        ds2 = docgia.laydocgia()
        Cb_hotendg.DataSource = ds2
        Cb_hotendg.DisplayMember = "HoTen"
        Cb_hotendg.ValueMember = "MaDG"
        Cb_hotendg.SelectedIndex = 0

        Dim tensach As New SachBUS()
        Dim ds3 As New List(Of SachDTO)
        ds3 = tensach.LaySach()
        Cb_tensach.DataSource = ds3
        Cb_tensach.DisplayMember = "TenSach"
        Cb_tensach.ValueMember = "MaSach"
        Cb_tensach.SelectedIndex = 0
        ' LoadData()
    End Sub

    Private Sub btnghinhanmatsach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnghinhanmatsach.Click
        Dim ghDTO As New MatSachDTO()
        'lay du lieu tu cac control 
        ghDTO.TienPhat = txttienphat.Text.Trim()
        ghDTO.MaSach = Cb_tensach.SelectedValue 'ComboBox_bangcap.Items(ComboBox_bangcap.SelectedIndex) 
        ghDTO.MaDG = Convert.ToInt32(Cb_hotendg.SelectedValue)
        ghDTO.MaNV = Convert.ToInt32(Cb_nguoighinnhan.SelectedValue)
        ghDTO.NgayGhiNhan = dtpngayghinhan.Value.ToLongDateString()
        'Dim strSQL As String = "insert into NhanVien(HoTen,MaBangCap,MaBoPhan,MaChucVu,DiaChi,DienThoai,NgaySinh) values('" + nvDTO.HoTen.ToString() + "'," + nvDTO.MaBangCap.ToString() + "," + nvDTO.MaBoPhan.ToString() + "," + nvDTO.MaChucVu.ToString() + ",'" + nvDTO.DiaChi.ToString() + "','" + nvDTO.DienThoai.ToString() + "','" + nvDTO.NgaySinh.ToString() + "')"
        ''goi BUS
        Dim kq As Integer
        Dim bus As New MatSachBUS()
        kq = bus.ghinhanmasach(ghDTO)

        If kq = 1 Then
            MessageBox.Show("them thanh cong")

        Else
            MessageBox.Show("them that bai")
        End If

    End Sub
End Class